package com.cz.video.website.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import com.cz.video.common.annotation.LegalValidate;
import com.cz.video.common.annotation.Log;
import com.cz.video.common.core.controller.BaseController;
import com.cz.video.common.core.domain.PageQuery;
import com.cz.video.common.core.domain.R;
import com.cz.video.common.core.page.TableDataInfo;
import com.cz.video.common.enums.BusinessType;
import com.cz.video.common.exception.ServiceException;
import com.cz.video.website.domain.WebsitePlayLogs;
import com.cz.video.website.domain.bo.WebsitePlayLogsBo;
import com.cz.video.website.service.IWebsitePlayLogsService;
import com.cz.video.system.api.RemoteUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 播放记录表 前端控制器
 * </p>
 *
 * @author LLF
 * @since 2023-10-16
 */
@Tag(name = "播放记录表")
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/website-play-logs")
public class WebsitePlayLogsController extends BaseController {

    public final IWebsitePlayLogsService websitePlayLogsService;
    private final RemoteUserService userService;

    //    @SaCheckPermission("website:PlayLogs:add")
    /**
     * 添加播放记录表
     * @param websitePlayLogs
     * @return
     */
    @SaCheckPermission("website:PlayLogs:add")
    @Operation(summary = "添加播放记录表")
    @Log(title = "添加播放记录表", businessType = BusinessType.INSERT)
    @PostMapping("")
    @LegalValidate
    public R<Void> add(@RequestBody @Validated WebsitePlayLogs websitePlayLogs){
        return toAjax(websitePlayLogsService.insertPlayLogs(websitePlayLogs));
    }

    /**
     * 删除播放记录表
     * @param id
     * @return
     */
    @SaCheckPermission("website:PlayLogs:delete")
    @Operation(summary = "删除播放记录表")
    @Log(title = "删除播放记录表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public R<Void> delete(@PathVariable int id){
        int result = websitePlayLogsService.deleteById(id);
        if (result > 0) {
            return toAjax(result);
        } else {
            throw new ServiceException("删除播放记录表失败，该播放记录表不存在。");
        }
    }

    /**
     * 修改播放记录表
     */
    @Operation(summary = "修改播放记录表")
    @SaCheckPermission("website:PlayLogs:edit")
    @Log(title = "播放记录表管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@Validated @RequestBody WebsitePlayLogsBo websitePlayLogs) {
        return toAjax(websitePlayLogsService.updatePlayLogs(websitePlayLogs));
    }

    /**
     * 获取播放记录表
     */
    @SaCheckPermission("website:PlayLogs:list")
    @GetMapping("/list")
    public TableDataInfo list(WebsitePlayLogsBo websitePlayLogs, PageQuery pageQuery) {
        return websitePlayLogsService.selectPagePlayLogsList(websitePlayLogs, pageQuery);
    }

}
